﻿using System;
using System.Data;
using System.Configuration;
using System.Web;

namespace imarks.Utility.Security
{
    /// <summary>
    /// MD5字符串加密
    /// 2011-05-09 陈震
    /// </summary>
    public class MD5
    {
        /// <summary>
        /// 普通MD5加密
        /// </summary>
        /// <param name="MD5">加密字符串</param>
        /// <returns>加密后的字符串</returns>
        public static string Encoding(string MD5)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(MD5.ToString(), "MD5").ToLower();
        }

        /// <summary>
        /// 判断是否和加密后的字符串相等
        /// </summary>
        /// <param name="str">要进行加密的字符串</param>
        /// <param name="MD5">已加密MD5字符</param>
        /// <returns>是否相等</returns>
        public static bool Equals(string str, string strMD5)
        {
            String s = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            if (str.Equals(strMD5.ToLower()))
                return true;
            return false;
        }
    }
}
